package com.xh.petdogexpert.user.service.imp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xh.petdogexpert.base.BaseException;
import com.xh.petdogexpert.base.ValudateForm;
import com.xh.petdogexpert.user.dto.Doctor;
import com.xh.petdogexpert.user.mapper.DoctorMapper;
import com.xh.petdogexpert.user.service.IDoctorService;

@Transactional
@Service
public class DoctorServiceImp implements IDoctorService {

	@Autowired
	DoctorMapper doctorMapper;

	@Autowired
	ValudateForm valudateForm;

	private Logger logger = LoggerFactory.getLogger(DoctorServiceImp.class);

	public Doctor getDoctor(Doctor doctor) throws BaseException {

		if (doctor == null || doctor.getUid() == null) {
			throw new BaseException("出错, 无法获取用户ID");
		}

		Integer res = doctorMapper.haveDoctorRecord(doctor.getUid());
		logger.debug("res  " + res);
		if (res == null) {
			int addRes = doctorMapper.addDoctor(doctor);
			if (addRes < 1) {
				throw new BaseException("出错, 新增兽医失败");
			}
			return doctor;
		} else {
			doctor = doctorMapper.getDoctor(doctor);
			return doctor;
		}
	}

	public int updateDoctor(Doctor doctor) throws BaseException {
		int updateRes = doctorMapper.updateDoctor(doctor);

		if (updateRes < 1) {
			throw new BaseException("出错, 更新兽医失败");
		}
		return updateRes;
	}

	public int deleteDoctor(Doctor doctor) throws BaseException {
		// TODO Auto-generated method stub
		return 0;
	}

}
